package com.hzjh.base.ext.widget.textview

import android.graphics.Canvas
import android.graphics.Paint
import android.graphics.drawable.Drawable
import android.text.style.ImageSpan

class MyImageSpan @JvmOverloads constructor(
    drawable: Drawable,
) : ImageSpan(drawable) {
    override fun draw(
        canvas: Canvas,
        text: CharSequence?,
        start: Int,
        end: Int,
        x: Float,
        top: Int,
        y: Int,
        bottom: Int,
        paint: Paint
    ) {
        val fm = paint.fontMetricsInt
        val transY = (y + fm.descent + y + fm.ascent) / 2.0f - drawable.bounds.bottom / 2.0f
        canvas.save()
        canvas.translate(x, transY)
        drawable.draw(canvas)
        canvas.restore()
    }


}